//
//  TFCommonPaddingTableViewItemCell.m
//  cetc-uzerme-ios
//
//  Created by Du Kai on 2020/9/2.
//Copyright © 2020 dkv587. All rights reserved.
//

#import "TFCommonPaddingTableViewItemCell.h"
#import <Masonry/Masonry.h>

@interface TFCommonPaddingTableViewItemCell ()

@property (nonatomic, strong) UIView *lineView;

@end

@implementation TFCommonPaddingTableViewItemCell
@dynamic tableViewItem;

#pragma mark - Cell life cycle
- (void)cellLoadSubViews {
    [super cellLoadSubViews];
    
    self.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.f];
    
    [self addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(ceil(self.tableViewItem.lineHeight));
        make.left.mas_equalTo(20.f);
        make.right.mas_equalTo(-20.f);
        make.bottom.mas_equalTo(0.f);
    }];
}

- (void)cellWillAppear {
    [super cellWillAppear];
    
    self.backgroundColor = self.tableViewItem.viewBackgroundColor;
    self.lineView.backgroundColor = self.tableViewItem.lineColor;
    if (self.tableViewItem.lineHeight == 0.f) {
        self.lineView.hidden = YES;
    } else {
        self.lineView.hidden = NO;
        [self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(self.tableViewItem.lineHeight);
        }];
    }
}

- (void)cellDidDisappear {
    [super cellDidDisappear];
    //clear subviews UI at here.
}

#pragma mark - 创建界面控件
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithRed:230/255.0 green:237/255.0 blue:246/255.0 alpha:1.f];
    }
    return _lineView;
}

@end
